package cn.easybuy.service.order;

import cn.easybuy.dao.OrderMapper;
import cn.easybuy.pojo.Order;
import cn.easybuy.service.orderdetail.OrderDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private OrderDetailService orderDetailService;

    @Override
    @Transactional
    public boolean saveOrder(Order order) {
        this.save(order);
        order.getOrderDetailList().forEach(
                orderDetail -> {orderDetail.setOrderId(order.getId());}
        );
        /*for(OrderDetail orderDetail : order.getOrderDetailList()){
            orderDetail.setOrderId(order.getId());
        }*/
        orderDetailService.saveBatch(order.getOrderDetailList());
        return true;
    }
}

